package br.com.foxinline.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author elyjunior
 */
public class ConverterStringDate {

    public static void main(String[] args) {


        Date suaData = new Date();

        Calendar calendario = Calendar.getInstance();
        calendario.setTime(suaData);

        int dia = calendario.get(Calendar.DAY_OF_MONTH);
        int mes = calendario.get(Calendar.MONTH);
        int ano = calendario.get(Calendar.YEAR);

        GregorianCalendar calendarioGregoriano = new GregorianCalendar();
        calendarioGregoriano.setTime(suaData);

        String sDia = String.valueOf(calendarioGregoriano.get(GregorianCalendar.DAY_OF_MONTH));
        String sMes = String.valueOf(calendarioGregoriano.get(GregorianCalendar.MONTH));
        String sAno = String.valueOf(calendarioGregoriano.get(GregorianCalendar.YEAR));
        
        // Ultimo dia do Mes
        
//        String uDia = String.valueOf(calendarioGregoriano.getActualMaximum(GregorianCalendar.DAY_OF_MONTH));
//        System.out.println(uDia);
        
        
//        try {
//            Date d = formataData(sDia+"/"+sMes+"/"+sAno);
////            System.out.println(d);
//        } catch (Exception ex) {
//            Logger.getLogger(ConverterStringDate.class.getName()).log(Level.SEVERE, null, ex);
//        }
        
        
    }
    
  
     public static Date formataData(String data) throws Exception {   
        if (data == null || data.equals(""))  
            return null;  

        Date date = null;  
        try {  
            DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");  
            date = (java.util.Date)formatter.parse(data);  
        } catch (ParseException e) {              
            throw e;  
        }  
        return date;  
    }
     
    public static String escreverData(Date d){
        d = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
        return df.format(c.getTime()); 
    }
}
